home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / addmem.c next >
C/C++ Source or Header  |  1985-10-30  |  5KB  |  200 lines

  1. /*************** READ.ME *************************/
  2.  
  3.  
  4. If you have a 512K memory board hanging off the side of your Amiga
  5. the following describes a way of
  6. adding memory which is not done from an auto-configured memory board.
  7.  
  8.         addmem_cmd.ld will give this memory to the exec to use.
  9.  
  10. This program takes two parameters, the starting and ending addresses
  11. in hex of memory to add.  For instance to add all of the ramcart:
  12.  
  13. addmem f00000 f7ffff
  14.  
  15. Caveat Empour:
  16. Our software should support extra non-display memory, BUT this
  17. has hardly been tested at all.  If you find problems, PLEASE
  18. REPORT them!
  19.  
  20. One already known bug, is you can't switch disks when you have
  21. the extra memory (in V27.5).  Don't even think about doing a
  22. diskcopy.  However for the brave and daring,
  23. you might create an EXECUTE file:
  24.  
  25. ; V27 version of RAM: commands.
  26. addmem f00000 f7ffff
  27. makedir ram:c
  28. run copy sys:c ram:c all
  29. cd comdir ram:c
  30.  
  31. ; V28 Version
  32. addmem f00000 f7ffff
  33. makedir ram:c
  34. run copy sys:c ram:c all
  35. ; Remove the current reference.
  36. assign c:
  37. ; Make a new reference.
  38. sys:c/assign c: ram:c
  39.  
  40. This will make all your commands "load" much faster.
  41. For those developing on an Amiga you might also want to put
  42. amiga.lib and lc.lib in the RAM:.
  43.  
  44.  
  45. More caveats are in order:
  46.  
  47.         This region of memory is searched by exec on system reset.
  48. If it finds something that it thinks it recognizes (as a library, for
  49. example), it will attempt to run it.  Power-off and on the ramcart to
  50. clear its memory if you suspect this.
  51.  
  52. If the first two words of the memory are the right magic numbers,
  53. kickstart will jump to this memory on reset.
  54.  
  55. Non-autoconfigurable memory is not supportable.  It is fine to use
  56. it for now -- we have no alternatives.  However, you system may well
  57. break once we get the expansion architecture in place.
  58.  
  59.  
  60. /*************** Makefile ************************/
  61. Amiga_VERS=../../../../
  62. SUBSYSNAME=addmem
  63.  
  64. MAKEFILE=Makefile
  65.  
  66. STARTUP=$(Amiga_VERS)internal/lib/startup.obj
  67. CFILES= addmem.c addmem_cmd.c
  68. OFILES= addmem.obj addmem_cmd.obj
  69.  
  70. all:    addmem.ld
  71.  
  72. .INCLUDE=$(Amiga_VERS)tools/makemeta
  73.  
  74.  
  75. /*************** addmem.with *********************/
  76. FROM *
  77. ../../../../internal/lib/startup.obj,*
  78. addmem.obj,*
  79. addmem_cmd.obj
  80. LIBRARY *
  81. /usr/commodore/amiga/V27/internal/lib/amiga.lib
  82.  
  83.  
  84. /*************** addmem.c ************************/
  85.  
  86. /*
  87.  *  addmem.c -- deallocate more memory for programs to use with
  88.  *              the memory allocator.
  89.  *  July 7, 1985  Version 1.0  Keith Stobie   Original version  
  90.  *
  91.  *  Link startup.obj, addmem.obj and addmem_cmd.obj using amiga.lib 
  92.  *  to create addmem.ld.
  93.  
  94.  */
  95.  
  96. #include "exec/types.h"
  97. #include "exec/exec.h"
  98. #include "exec/execbase.h"
  99.  
  100. addmem (lower,upper) 
  101.     long lower;   
  102.     long upper;
  103. {
  104.     struct ExecBase **SysBase = (struct ExecBase  **) 4;
  105.     struct MemHeader   *new_area;
  106.  
  107.     new_area = (struct MemHeader *) AllocMem (sizeof (struct MemHeader),
  108.                       MEMF_PUBLIC);
  109.  
  110.     if (new_area == 0) {
  111.    printf ("%s: unable to allocate memory to MemHeader!\n");
  112.    exit (10);
  113.     }
  114.  
  115.     new_area -> mh_Node.ln_Type = NT_MEMORY;
  116.     new_area -> mh_Attributes = MEMF_FAST | MEMF_PUBLIC;
  117.     new_area -> mh_Lower = (APTR) lower;
  118.     new_area -> mh_Upper = (APTR) upper;
  119.     new_area -> mh_Free = 0;
  120.  
  121.     printf ("lower=0x%lx, upper=0x%lx, new_area=0x%lx\n", lower,
  122.          upper, new_area);
  123.  
  124.     AddHead (&(*SysBase) -> MemList, new_area);
  125.  
  126.     Deallocate (new_area, lower, (upper - lower));
  127. }
  128.  
  129. /*************** addmem_cmd.c ********************/
  130. /* 
  131.  *  addmem_cmd.c   - CLI command to allow users to add memory by
  132.  *                   calling addmem().
  133.  *  First version,  Keith Stobie
  134.  *  Revised version, Carl Sassenrath
  135.  *  July 7, 1985   Version 1.0   Keith Stobie  First public version.
  136.  *
  137.  */
  138. #define VERSION "1.0"
  139.  
  140. #include <exec/types.h>
  141. #include <exec/exec.h>
  142. #include <exec/execbase.h>
  143.  
  144. char *program_name;
  145.  
  146. print_usage()
  147. {
  148.     printf( "%s: version %s\n", program_name, VERSION );
  149.     printf( "usage: %s <lower-hex-addr> <upper-hex-addr> \n", program_name );
  150.     exit( 5 );
  151. }
  152.  
  153. main(argc,argv)
  154.     int argc;
  155.     char *argv[];
  156. {
  157.     long    lower,
  158.             upper;
  159.  
  160.     program_name = *argv++;
  161.  
  162.     if (argc == 1) print_usage();
  163.     if (argc < 3) {
  164.        printf( "%s: Missing upper address!\n", program_name );
  165.        print_usage();
  166.     }
  167.  
  168.     lower = gethex (argv[0]);
  169.     upper = gethex (argv[1]);
  170.     addmem (lower, upper);
  171. }
  172.  
  173. long gethex(s)
  174.      char *s;
  175. {
  176.     long    num = 0;
  177.     char    ch;
  178.  
  179.     while ((ch = *s++) != 0) {
  180.       switch (ch) {
  181.          case '0': case '1': case '2': case '3': case '4': 
  182.          case '5': case '6': case '7': case '8': case '9': 
  183.             num = num * 16 + (ch - '0');
  184.             break;
  185.          case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 
  186.             num = num * 16 + (ch - 'a') + 10;
  187.             break;
  188.          case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 
  189.             num = num * 16 + (ch - 'A') + 10;
  190.             break;
  191.          default: 
  192.             printf ("Non hex digit found '%lc'\n", ch);
  193.             print_usage ();
  194.       }        /* switch */
  195.    }
  196.  
  197.    return num;
  198. }           /* gethex */
  199.  
  200.